﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

using Flit.Samples.StateMachine;

using sm=Flit.Samples.StateMachine;

using NUnit.Framework;

namespace Flit.Samples.Tests
{
    [TestFixture]
    public class StateMachineTest
    {
        [Test]
        public void StateAdvances()
        {
            TurnstileStateMachine sm = new TurnstileStateMachine(TurnstileStateMachine.State.Locked);
            sm.Accept(TurnstileStateMachine.Signal.Coin);
            Assert.AreEqual(TurnstileStateMachine.State.Unlocked, sm.CurrentState);
            sm.Accept(TurnstileStateMachine.Signal.Coin);
            Assert.AreEqual(TurnstileStateMachine.State.Unlocked, sm.CurrentState);
            sm.Accept(TurnstileStateMachine.Signal.Pass);
            Assert.AreEqual(TurnstileStateMachine.State.Locked, sm.CurrentState);
            sm.Accept(TurnstileStateMachine.Signal.Pass);
            Assert.AreEqual(TurnstileStateMachine.State.Violation, sm.CurrentState);
        }
        
        [Test]
        [ExpectedException(typeof(UnexpectedSignalException))]
        public void UnexpectedSignal()
        {
            TurnstileStateMachine sm = new TurnstileStateMachine(TurnstileStateMachine.State.Locked);
            sm.Accept(TurnstileStateMachine.Signal.Reset);
        }
    }
}
